;(function ($) {
  $(function () {
    var lock = false
    $('#J_order').removeClass('dn');
    var vm = new Vue({
      el: '#J_order',
      data: function () {
        return {
          order: [],
          show_btn: false,
          error: {
            show_error: false,
            msg: ''
          }
        }
      },
      created: function () {
        var order_no = $.getQueryString('order_no')
        var isFrom = $.getQueryString('is_from')
        var cancel_num = $.getQueryString('cancel_num') || ''
        var _this = this;
        this.show_btn = isFrom === 'list' ? false : true;
        $.mAjax({
          url: '/order/get-cancel-detail',
          data: {
            order_no: order_no,
            cancel_num: cancel_num
          },
          success: function (res) {
            if (res.status == 1) {
              _this.order = res.data
            } else {
              _this.error = {
                show_error: true,
                msg: res.error.errormsg
            }
            setTimeout(()=> {
                _this.error = {
                    show_error: false,
                    msg: ''
                }  
            }, 2000) 
            }
          }
        }, true)
      },
      methods: {
        hexiaoHandler: function(str) {
          var order_no = $.getQueryString('order_no')
          var cancel_no = $.getQueryString('cancel_no')
          var cancel_num = $.getQueryString('cancel_num') || 1
          var _this = this;
          if (lock) {
              return false;
          }            
          lock = true;
          layer.open({
            content: '您是否' + str + '?',
            btn: ['确定', '取消'],
            yes: function (index) {
              layer.close(index);              
              $.mAjax({
                url: '/order/cancel-order-by-hand',
                data: {
                  order_no: order_no,
                  cancel_no: cancel_no,
                  cancel_num: cancel_num
                },
                success: function (res) {
                  if (res.status == 1) {
                    location.href = './order-list.html'
                  } else {
                    if (res.error.errorno == '200009') {
                      layer.open({
                        content: res.error.errormsg,
                        btn: ['去上班', '取消'],
                        yes: function (index) {
                          location.href = '../index.html'
                          layer.close(index);
                        }
                      });
                    } else {
                      _this.error = {
                        show_error: true,
                        msg: res.error.errormsg
                      }
                      setTimeout(() => {
                        _this.error = {
                          show_error: false,
                          msg: ''
                        }
                      }, 2000)
                    }
                  }
                  lock = false;
                },
                error: function() {
                  lock = false;
                }
              })
            }
          });
        }
      }
      
    })
  })
})(jQuery)